// 翻滚加载(热搜部分)
// 思路;向下翻滚，页数加一，请求发送一次，渲染一次
var currentPage = 1;
// 判断数据是否为0
function judge(data) {
  if (data.transmit == 0) {
    data.transmit = "分享";
  }
  if (data.likes == 0) {
    data.likes = "点赞";
  }
  if (data.comment == 0) {
    data.comment = "评论";
  }
}
let uid = document.querySelector(".userInfo").getAttribute("uid");
function getrestMsg() {
  $(window).scroll(function () {
    if (
      Math.round($(window).scrollTop() + $(window).height()) ==
      $(document).height() - 5
    ) {
      currentPage++;
      $.ajax({
        url: `/weibo/my/getLoadedMyBlog?id=${uid}&pageNo=${currentPage}&pageSize=10`,
        type: "get",
        data: {},
        success: function (result) {
          console.log("数据加载");
          console.log(result);
          let user = getInfo();
          let allnews = document.querySelector(".allnews");
          for (let i = 0; i < result.length; i++) {
            judge(result[i]);
            let myBlog = result[i];
            let text;
            if (myBlog.label) {
              text = ` <a class="color" href="/blog/skipToBlog?label=${myBlog.label}" >#${myBlog.label}#</a>
<span class="blogText" >
    ${myBlog.text}
   </span>`;
            } else {
              text = `<span class="blogText" >
                ${myBlog.text}
               </span>`;
            }
            if (myBlog.isMy == 0) {
              allnews.innerHTML += ` <div class="news add" bid="${myBlog.id}" uid="${myBlog.uid}" >
                <div>
                    <div class="news-top">
                        <a href="/weibo/user/toOnesInfo(id=${myBlog.uid}" class="head-link">
                            <div class="head">
                                <img
                                        alt="发布者头像"
                                        class="blogHeadPhoto"
                                        src="${myBlog.myInfo.avatarUrl}"
                                />
                            </div>
                        </a>
                        <div class="top-details">
                            <a href="" class="name" >
                                <p class="userName" >${myBlog.myInfo.username}</p>
                            </a>
                            <p class="time"> ${myBlog.time}</p>
                        </div>
                        <div class="report-remove " >
                            <div class="rm-icon" bid="${myBlog.id}" otherid="${uid}" onclick="reportfn(this)"><i class="iconfont">&#xe62e;</i></div>
                            <ul class="rm-detials hidden">
                                <li class="tip-off-li" bid="${myBlog.id}">投诉</li>
                                <li class="remove-li" onclick="removeBlog(this)" bid="${myBlog.id}" >删除</li>
           
                            </ul>
                        </div>
                    </div>
                    <div class="news-container">${text} <div class="news-content">
                            
                        </div>
                    </div>
                    <div class="foot">
                        <div class="share">
                            <i class="iconfont">&#xe62f;</i>
                            <span class="shareNum" >${myBlog.transmit}</span>
                        </div>
                        <div class="assess" bid="${myBlog.id}">
           
                            <i class="iconfont">&#xe695;</i>
                            <span class="commentNum">${myBlog.comment}</span>
                            </a>
                        </div>
                        
                        <div class="like">
                            <i class="iconfont">&#xe62b;</i>
                            <span class="likesNum" >${myBlog.likes}</span>
                        </div>
                    </div>
                    <div class="spread">
                       <textarea
                               placeholder="请发布你的评论"
                               class="comment-text"
                       ></textarea>
                        <span class="comment-ddl">还可输入140字</span>
                        <button class="comment-btn disable">评论</button>
                        <div class="comment" > 
                        </div>
                    </div>
                </div>
               `;
              more();
              assessBtn();
              commentfn();
              commentlimit();
              YesOrNo();
              func();
              replyWindow();
              collapsefn();
              switchoverfn();
            } else if (myBlog.usMy == 1) {
              allnews.innerHTML += `  <div class="news add" bid="${myBlog.id}" uid="${myBlog.uid}" >
                <div >
                <div class="news-top">
                    <a href="/weibo/user/toOnesInfo?id=${myBlog.uid}" class="head-link">
                        <div class="head">
                            <img
                                    alt="发布者头像"
                                    class="blogHeadPhoto"
                                    src="${myBlog.myInfo.avatarUrl}"
                            />
                        </div>
                    </a>
                    <div class="top-details" >
                        <a href="" class="name" >
                            <p class="userName" >${myBlog.myInfo.username}</p>
                        </a>
                        <p class="time" >${myBlog.transmitTime}</p>
                    </div>
                    <div class="report-remove " >
                        <div class="rm-icon" bid="${myBlog.id}" otherid="${user.id}" onclick="reportfn(this)"><i class="iconfont">&#xe62e;</i></div>
                        <ul class="rm-detials hidden">
                            <li class="tip-off-li" bid="${myBlog.id}">投诉</li>
                            <li class="remove-li" onclick="removeBlog(this)" bid="${myBlog.id}" >删除</li>
                        </ul>
                    </div>
       
                </div>
                <p style="margin-left: 75px">转发微博</p>
       
                <div class="transBlogContent" style="background-color: #f6f8fa;margin-top: 20px">
                    <div class="content-top" style="margin-left: 55px">
                        <div class="top-details">
                            <a href="" class="name">
                                <p class="userName"  style="font-size: 15px">${myBlog.otherInfo.username}</p>
                            </a>
                            <p class="time" >${myBlog.time}</p>
                        </div>
                    </div>
                    <div class="news-container">${text}
                
                       
                        <div class="news-content">
                           
                        </div>
                    </div>
                </div>
                <div class="foot">
                    <div class="share">
                        <i class="iconfont">&#xe62f;</i>
                        <span class="shareNum" >${myBlog.transmit}</span>
                    </div>
                    <div class="assess" bid="${myBlog.id}">
       
                        <i class="iconfont">&#xe695;</i>
                        <span class="commentNum">${myBlog.comment}</span>
                        </a>
                    </div>
                    <!--                <div class="store">-->
                    <!--                    <i class="iconfont">&#xe647;</i>-->
                    <!--                    <span>收藏</span>-->
                    <!--                </div>-->
                    <div class="like">
                        <i class="iconfont">&#xe62b;</i>
                        <span class="likesNum" >${myBlog.likes}</span>
                    </div>
                </div>
                <div class="spread">
                   <textarea
                           placeholder="请发布你的评论"
                           class="comment-text"
                   ></textarea>
                    <span class="comment-ddl">还可输入140字</span>
                    <button class="comment-btn disable">评论</button>
                    <div class="comment" >
                        
                        
                    </div>
                </div>
            </div>
        </div></div>`;
            }
            more();
            assessBtn();
            commentlimit();
            commentfn();
            YesOrNo();
            func();
            replyWindow();
            collapsefn();
            switchoverfn();

            let add = document.getElementsByClassName("add")[i];
            let content = add.querySelector(".news-content");
            let picture = result[i].pictureUrl;
            if (picture.length > 0) {
              for (let j = 0; j < picture.length; j++) {
                content.innerHTML += `<div class="news-content-img"  >
          <img src="${picture[j]}"alt="" onclick="showModel(this)">
        </div>`;
              }
            }
          }
          if (result.length >= 0 && result.length < 10) {
            document.querySelector(".none").classList.remove("hidden");
          }

          more();
          assessBtn();
          commentfn();
          YesOrNo();
          func();
          commentlimit();
          replyWindow();
          collapsefn();
          switchoverfn();
        },
      });
    }
  });
}
getrestMsg();
